/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef TEST_UTILS_MOCK_BUS_H
#define TEST_UTILS_MOCK_BUS_H

#include "internal/bus/bus_base/bus.h"

#include <memory>
#include <stdexcept>
#include <string>
#include <vector>

namespace test_utils {

struct block_write_call {
    uint32_t             offset;
    std::vector<uint8_t> write_buffer;
    std::vector<uint8_t> out_buffer;
};

class mock_bus : public dev::bus_base, public std::enable_shared_from_this<mock_bus> {
public:
    mock_bus() = default;

    uint32_t read(ACCESS_DATA_S& input) override;
    uint32_t write(ACCESS_DATA_S& input) override;
    uint8_t  get_id() override;
    void     bus_lock() override;
    void     bus_unlock() override;

    void set_id(uint8_t id);

    std::shared_ptr<mock_bus> shared_from_this();

    std::vector<block_write_call> block_write_calls;
    int32_t                       block_write_result = HAS_OK;
    std::string                   block_write_error;
    bool                          throw_on_block_write = false;

    int read_call_count   = 0;
    int lock_call_count   = 0;
    int unlock_call_count = 0;

private:
    uint8_t m_id = 0;
};

} // namespace test_utils

#endif // TEST_UTILS_MOCK_BUS_H
